package com.example.tms.mapper;

import com.example.tms.bean.CarView;
import com.example.tms.bean.RoadView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;


/**
 * 车辆视图
 */
@Repository("carView")
public interface CarVMapper extends JpaRepository<CarView, String>, JpaSpecificationExecutor<CarView> {

    //查询车辆信息（车辆id）
    CarView findByClidAndSfcz(String clid, boolean sfcz);
    //查询车辆信息（车牌号）
    CarView findByCphAndSfcz(String cph, boolean sfcz);

    //运单发车
    @Query(value = "update car_info set clzt = '已分配' = ?2 where clid = ?1", nativeQuery = true)
    @Modifying
    @Transactional
    void startWaybill(String clid, String clzt);

    //查询车辆数量
    @Query(value = "select  count(clid)  from car_info where sffp='已分配' and sfcz = true", nativeQuery = true)
    Integer findCarFenpei();

    //查询车辆数量
    @Query(value = "select  count(clid)  from car_info where sffp!='已分配' and sfcz = true", nativeQuery = true)
    Integer findCarWeiFenpei();

    //查询车辆数量
    @Query(value = "select  count(clid)  from car_info where clzt='维修' and sfcz = true", nativeQuery = true)
    Integer findCarweixiu();

    //查询车辆数量
    @Query(value = "select  count(clid)  from car_info where clzt='停运' and sfcz = true", nativeQuery = true)
    Integer findCartingyun();

    //查询车辆数量
    @Query(value = "select  count(clid)  from car_info where clzt='报废' and sfcz = true", nativeQuery = true)
    Integer findCarbaofei();

    //查询车辆数量
    @Query(value = "select  count(clid)  from car_info where clzt='转出' and sfcz = true", nativeQuery = true)
    Integer findCarzhuanchu();

    //查询车辆数量
    @Query(value = "select  count(clid)  from car_info where clzt='可用' and sfcz = true", nativeQuery = true)
    Integer findCarkeyong();

}
